/*
 * @Author: your name
 * @Date: 2021-10-12 17:36:33
 * @LastEditTime: 2021-10-12 23:08:42
 * @LastEditors: Please set LastEditors
 * @Description: 最开始的思路
 * @FilePath: \luogu\动态规划\模板问题\P1049 装箱问题\2main.c
 */
#include<stdio.h>

int main()
{
    int v,n;
    scanf("%d%d",&v,&n);

    int array[100];
    int i,j;
    for(i = 0;i < n;i++)
    {
        scanf("%d",&array[i]);
    }

    int f[20001] = {0};

    for(i = 0;i < n;i++)
    {
        for(j = v;j >= array[i];j--)
        {
            if(f[j] < f[j - array[i]] + array[i])
                f[j] = f[j - array[i]] + array[i];
        }
        for(int j=0; j<=v; j++){
            printf("f[%d] = %d\n",j,f[j]);
        }
        printf("\n");
        // systems("pause");
    }

    printf("%d",v-f[v]);
    return 0;
}